#import <Foundation/Foundation.h>
#import <sys/stat.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	if(argc!=2)
	{
		printf("Whose CommandName");
		exit(1);
	}
	char *path = getenv("PATH");
	
	char *pointer = path;
	char *start = path;
	char *end = path;
	struct stat statInfo;
	
	for(;*pointer!='\0';pointer++)
	{
		if(*pointer==':')
		{
			end = pointer-1;
			char* temp = (char *)malloc(sizeof(char)*(pointer-start+1));
			memset(temp,0,sizeof(char)*(pointer-start+1));
			strncpy(temp,start,sizeof(char)*(pointer-start));
			if(*end!='/')
				strcat(temp,"/");
			strcat(temp,argv[1]);

			
			if(stat(temp, &statInfo)==0)
			{
				printf("%s\n",temp);
			}
			//printf("%s\n",temp);
			start=pointer+1;
		}
		                                                       
	}

    [pool drain];
    return 0;
}		
